package com.iven.xie.code.generator.bean;


import lombok.Data;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 查询参数
 *
 * @author iven.xie
 */
@Data
public class QueryBean extends LinkedHashMap<String, Object> {
    private static final long serialVersionUID = 1L;
    /**
     * 当前页码
     */
    private int page = 1;
    /**
     * 每页条数
     */
    private int limit = 20;

    public QueryBean(Map<String, Object> params) {
        this.putAll(params);

        //分页参数
        if (Objects.nonNull(params.get("page"))) {
            this.page = Integer.parseInt(params.get("page").toString());
        }
        if (Objects.nonNull(params.get("limit"))) {
            this.limit = Integer.parseInt(params.get("limit").toString());
        }
        this.put("offset", (page - 1) * limit);
        this.put("page", page);
        this.put("limit", limit);
    }
}
